Just Run Example from Plotly Website and save as Static Image¶

The example comes from the Plotly website. See the following link: https://plotly.com/python/ternary-contour/. I did not change anything. I just saved the plot as a static image. I have used svg format, not for a particular reason. I just wanted to try it out, since not all libraries support svg format. The instructions I followed are from the following link: https://plotly.com/python/static-image-export/.

In [ ]:
import plotly.figure_factory as ff
import numpy as np
Al = np.array([0. , 0. , 0., 0., 1./3, 1./3, 1./3, 2./3, 2./3, 1.])
Cu = np.array([0., 1./3, 2./3, 1., 0., 1./3, 2./3, 0., 1./3, 0.])
Y = 1 - Al - Cu
# synthetic data for mixing enthalpy
# See https://pycalphad.org/docs/latest/examples/TernaryExamples.html
enthalpy = (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1)**2
fig = ff.create_ternary_contour(np.array([Al, Y, Cu]), enthalpy,
                                pole_labels=['Al', 'Y', 'Cu'],
                                interp_mode='cartesian')
fig.show()
In [ ]:
import os

# Get the current folder of the notebook. See the following stackoverflow answer for
# more details: https://stackoverflow.com/a/53958599
current_folder_of_notebook = globals()['_dh'][0]
image_dir = os.path.join(current_folder_of_notebook, 'images')
os.makedirs(image_dir, exist_ok=True)
In [ ]:
# Save the figure as a svg file.
fig.write_image(os.path.join(image_dir, 'plotly_ternary_contour.svg'))